package com.space;

import java.util.TimerTask;
import java.util.Timer;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Game implements ApplicationListener, InputProcessor {
	private SpriteBatch batch;
	private Texture texture;
	private Sprite sprite;
	private PlayerShip mainShip;
	private Timer timer;
	private TimerTask timertask;
	private BitmapFont font;
	private boolean flag = false;
	
	private void createTimerTask()
	{
		timertask = new TimerTask() {
			@Override
			public void run() {
				flag = !flag;
			}
		};
		timer = new Timer();
		timer.schedule(timertask, 0, 1000);
		timertask.run();
		
	}
	
	
	@Override
	public void create() {
		batch = new SpriteBatch();
		texture = new Texture(Gdx.files.internal("bugship.png"));
//		sprite = new Sprite(texture);
		mainShip = new PlayerShip(texture);
		font = new BitmapFont();
		font.setColor(Color.RED);
		createTimerTask();
	}

	@Override
	public void resume() {

	}

	@Override
	public void render() {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		batch.begin();
		mainShip.Movement();
		batch.draw(mainShip, mainShip.getX(), mainShip.getY());
//		mainShip.draw(batch);
		String test = "x: " + mainShip.getX();
		font.draw(batch, test, Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 2);
		test = "y: " + mainShip.getY();
		font.draw(batch, test, Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 3);
		
		if (Gdx.input.isTouched())
		{
			test = "touched y: " + (Gdx.graphics.getHeight() - Gdx.input.getY() );
			font.draw(batch, test, Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 4);
			test = "miinus" + ((Gdx.graphics.getHeight() - Gdx.input.getY()) - mainShip.getY());
			font.draw(batch, test, Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 5);
			
		}
		
		
		if (flag)
		{
			font.draw(batch, "Flag: True", Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
		}
		else
		{
			font.draw(batch, "Flag: False", Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
		}
		int fps = Gdx.graphics.getFramesPerSecond();
		font.draw(batch, String.valueOf(fps), 50, 50);
		batch.end();

	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}


	@Override
	public boolean keyDown(int keycode) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean keyUp(int keycode) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean keyTyped(char character) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean touchDown(int x, int y, int pointer, int button) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean touchUp(int x, int y, int pointer, int button) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean touchDragged(int x, int y, int pointer) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean touchMoved(int x, int y) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean scrolled(int amount) {
		// TODO Auto-generated method stub
		return false;
	}

}
